﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Konst3d.Efficiency.Suite;

namespace DevUI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void uiOpenSuiteMainMenuItem_Click(object sender, EventArgs e)
        {
            if (uiOpenSuiteDlg.ShowDialog() == DialogResult.OK)
            {
                OpenSuite(uiOpenSuiteDlg.FileName);
            }
        }

        private void uiCreateSuiteMainMenuItem_Click(object sender, EventArgs e)
        {
            CreateSuite();
        }

        private void uiAddMonitorTSButton_Click(object sender, EventArgs e)
        {
            AddMonitor();
        }

        private void uiMonitorsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (uiMonitorsListBox.SelectedIndex >= 0)
            {
                MonitorListItem item = (MonitorListItem)uiMonitorsListBox.SelectedItem;

                ShowMonitorInfo(item.ID);
            }
        }

        private void uiSaveMonitorChangesButton_Click(object sender, EventArgs e)
        {
            if (uiMonitorsListBox.SelectedIndex >= 0)
            {
                MonitorListItem item = (MonitorListItem)uiMonitorsListBox.SelectedItem;

                SaveMonitor(item.ID);
            }
        }

        private void uiCloseSuiteTSButton_Click(object sender, EventArgs e)
        {
            if (_suite != null)
            {
                CloseSuite();
            }
        }

        private void uiRemoveMonitorTSButton_Click(object sender, EventArgs e)
        {
            if (uiMonitorsListBox.SelectedIndex >= 0)
            {
                MonitorListItem item = (MonitorListItem)uiMonitorsListBox.SelectedItem;

                RemoveMonitor(item.ID);

                if (uiMonitorsListBox.Items.Count > 0)
                {
                    uiMonitorsListBox.SelectedIndex = 0;
                }
            }
        }

        private void uiMonitorsListBox_DoubleClick(object sender, EventArgs e)
        {
            if (uiMonitorsListBox.SelectedIndex >= 0)
            {
                MonitorListItem item = (MonitorListItem)uiMonitorsListBox.SelectedItem;

                ShowMonitorStatistics(item.ID);
            }
        }

        private void uiSummaryOpenDailyReportButton_Click(object sender, EventArgs e)
        {
            OpenDailyReport();
        }

        // temp
        private void uiSummaryPage_Click(object sender, EventArgs e)
        {
            MessageBox.Show("click");
        }

        // temp
        private void uiSummaryPage_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("dbl click");
        }

        private void uiDeleteSuiteTSButton_Click(object sender, EventArgs e)
        {
            DeleteSuite();
        }

        private void uiAddMileTSButton_Click(object sender, EventArgs e)
        {
            AddMilestone();
        }

        private void uiMilesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var entry = uiMilesListBox.SelectedItem as MilestoneListItem;

            if (entry != null)
            {
                ShowMilestoneInfo(entry.Milestone);
            }
        }

        private void uiRemoveMileTSButton_Click(object sender, EventArgs e)
        {
            var entry = uiMilesListBox.SelectedItem as MilestoneListItem;

            if (entry != null)
            {
                RemoveMilestone(entry.ID);
            }
        }

        private void uiSaveMileButton_Click(object sender, EventArgs e)
        {
            var entry = uiMilesListBox.SelectedItem as MilestoneListItem;

            if (entry != null)
            {
                SaveMilestone(entry.ID);
            }
        }

        private void uiMilesCalendar_DateChanged(object sender, DateRangeEventArgs e)
        {
            ShowMilesForDate(e.Start);
        }

        private void uiAddTaskTSButton_Click(object sender, EventArgs e)
        {
            AddTask();
        }

        private void uiRemoveTaskTSButton_Click(object sender, EventArgs e)
        {
            var item = uiTasksListBox.SelectedItem as TaskListItem;

            if (item != null)
            {
                RemoveTask(item.ID);
            }
        }

        private void uiTaskStateComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            TaskState state = (TaskState)uiTaskStateComboBox.SelectedIndex;

            ShowTaskList(state);
        }

        private void uiTasksListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = uiTasksListBox.SelectedItem as TaskListItem;

            if (item != null)
            {
                ShowTaskInfo(item.Task);
            }
        }

        private void uiSaveTaskButton_Click(object sender, EventArgs e)
        {
            var item = uiTasksListBox.SelectedItem as TaskListItem;

            if (item != null)
            {
                SaveTask(item.Task);
            }
        }

        private void uiAddCountDownTSButton_Click(object sender, EventArgs e)
        {
            AddCountDown();
        }

        private void uiRemoveCountDownTSButton_Click(object sender, EventArgs e)
        {
            var item = uiCountDownsListBox.SelectedItem as CountDownListItem;

            if (item != null)
            {
                RemoveCountDown(item.ID);
            }
        }

        private void uiCountDownsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = uiCountDownsListBox.SelectedItem as CountDownListItem;

            if (item != null)
            {
                ShowCountDownInfo(item.Timer);
            }
        }

        private void uiCountDownSaveButton_Click(object sender, EventArgs e)
        {
            var item = uiCountDownsListBox.SelectedItem as CountDownListItem;

            if (item != null)
            {
                SaveCountDown(item.Timer);
            }
        }

        private void uiAddMonitoringGroupTSButton_Click(object sender, EventArgs e)
        {
            AddMonitoringGroup();
        }

        private void uiRemoveMonitoringGroupTSButton_Click(object sender, EventArgs e)
        {
            var group = uiMonitoringGroupsListBox.SelectedItem as MonitoringGroupListItem;

            if (group != null)
            {
                RemoveMonitoringGroup(group.ID);
            }
        }

        private void uiMonitoringGroupsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var group = uiMonitoringGroupsListBox.SelectedItem as MonitoringGroupListItem;

            if (group != null)
            {
                ShowMonitoringGroupInfo(group.Group);
            }
        }

        private void uiSaveMonitoringGroupButton_Click(object sender, EventArgs e)
        {
            var group = uiMonitoringGroupsListBox.SelectedItem as MonitoringGroupListItem;

            if (group != null)
            {
                SaveMonitoringGroup(group.Group);
            }
        }

        private void uiMonitoringGroupAvailableTasksListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var selected = uiMonitoringGroupAvailableTasksListBox.SelectedItem;

            if (selected != null)
            {
                uiMonitoringGroupAvailableTasksListBox.Items.Remove(selected);
                uiMonitoringGroupAddedTasksListBox.Items.Add(selected);
            }
        }

        private void uiMonitoringGroupAddedTasksListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var selected = uiMonitoringGroupAddedTasksListBox.SelectedItem;

            if (selected != null)
            {
                uiMonitoringGroupAddedTasksListBox.Items.Remove(selected);
                uiMonitoringGroupAvailableTasksListBox.Items.Add(selected);
            }
        }

        private void uiMonitoringGroupAvailableMonitorsListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var selected = uiMonitoringGroupAvailableMonitorsListBox.SelectedItem;

            if (selected != null)
            {
                uiMonitoringGroupAvailableMonitorsListBox.Items.Remove(selected);
                uiMonitoringGroupAddedMonitorsListBox.Items.Add(selected);
            }
        }

        private void uiMonitoringGroupAddedMonitorsListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var selected = uiMonitoringGroupAddedMonitorsListBox.SelectedItem;

            if (selected != null)
            {
                uiMonitoringGroupAddedMonitorsListBox.Items.Remove(selected);
                uiMonitoringGroupAvailableMonitorsListBox.Items.Add(selected);
            }
        }

        private void uiBuyListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selected = uiBuyListBox.SelectedItem as BuyListItem;

            if (selected != null)
            {
                ShowBuyInfo(selected.Buy);
            }
        }

        private void uiAddBuyTSButton_Click(object sender, EventArgs e)
        {
            AddBuy();
        }

        private void uiRemoveBuyTSButton_Click(object sender, EventArgs e)
        {
            var selected = uiBuyListBox.SelectedItem as BuyListItem;

            if (selected != null)
            {
                RemoveBuy(selected.Buy.ID);
            }
        }

        private void uiSaveBuyButton_Click(object sender, EventArgs e)
        {
            var selected = uiBuyListBox.SelectedItem as BuyListItem;

            if (selected != null)
            {
                SaveBuy(selected.Buy);
            }
        }

        private void uiAddNoteTSButton_Click(object sender, EventArgs e)
        {
            AddNote();
        }

        private void uiRemoveNoteTSButton_Click(object sender, EventArgs e)
        {
            var selected = uiNotesListBox.SelectedItem as NoteListItem;

            if (selected != null)
            {
                RemoveNote(selected.Note.ID);
            }
        }

        private void uiNotesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selected = uiNotesListBox.SelectedItem as NoteListItem;

            if (selected != null)
            {
                ShowNoteInfo(selected.Note);
            }
        }

        private void uiNoteSaveButton_Click(object sender, EventArgs e)
        {
            var selected = uiNotesListBox.SelectedItem as NoteListItem;

            if (selected != null)
            {
                SaveNote(selected.Note);
            }
        }
    }
}
